const mongoose = require("./db");
//用户表
let UserM = new mongoose.Schema({
  name: String,
  password: String,
  phone: String,
  avatar: String,
});
//商品类别表
let typeSchema = new mongoose.Schema({
  name: String,
});
//商品表
let ancientSchema = new mongoose.Schema({
  img: String,
  title: String,
  content: String,
  author: {
    type: mongoose.Types.ObjectId,
    ref: "author",
  },
  tag: Array,
  type: {
    type: mongoose.Types.ObjectId,
    ref: "type",
  },
});

//尺码款式表
let SizeM = new mongoose.Schema({
  size: [String],
  color: [String],
  productId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "ancient",
  },
});
//商家表
let authorSchema = new mongoose.Schema({
  name: String,
  img: String,
});
//购物车表
let CartM = new mongoose.Schema({
  userId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "user",
  },
  productId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "ancient",
  },
  sizeId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "size",
  },
  //选中的尺码
  size: String,
  //选中的颜色
  color: String,
  count: Number,
});

//订单表
let OrderM = new mongoose.Schema({
  userId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "user",
  },
  productId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "ancient",
  },
  size: String,
  color: String,
});

let dynamicState = new mongoose.Schema({
  imgPath: String,
  content: String,
  address: String,
  pubTime: {
    type: Date,
    default: Date.now(),
  },
  author: {
    type: mongoose.Types.ObjectId,
    ref: "author",
  },
  upvote: {
    type: Number,
    default: 0,
  },
  reviewNum: {
    type: Number,
    default: 0,
  },
  collect: {
    type: Number,
    default: 0,
  },
  dzShow: {
    type: Boolean,
    default: false,
  },
  scShow: {
    type: Boolean,
    default: false,
  },
  reviewShow: {
    type: Boolean,
    default: false,
  },
  height: Number,
  width: Number,
});
let chatSchema = new mongoose.Schema({
  leftId: String,
  leftName: String,
  leftAvatar: String,
  leftPhone: String,
  rightId: String,
  rightName: String,
  rightAvatar: String,
  rightPhone: String,
  chatContent: Array,
  roomId: String,

})
let merchantSchema = new mongoose.Schema({
  img: String,
  name: String,
  sell: Number,
  price: Number,
})
let ShopCarSchema = mongoose.Schema({
  Tname: String,
  children: [
    {
      Iurl: String,
      name: String,
      newprice: Number,
      price: Number,
      num: Number,
      isnow: Boolean,
    },
  ],
});
let ShopCarModel = mongoose.model("ShopCar", ShopCarSchema, "ShopCar");
let merchantModel = mongoose.model("merchant", merchantSchema, 'merchant')
let UserModel = mongoose.model("user", UserM, 'user');

let CartModel = mongoose.model("cart", CartM, 'cart');
let SizeModel = mongoose.model("size", SizeM, 'size');
let OrderModel = mongoose.model("order", OrderM, 'order');
let ancientModel = mongoose.model("ancient", ancientSchema, 'ancient');
let authorModel = mongoose.model("author", authorSchema, 'author')
let typeModel = mongoose.model("type", typeSchema, 'type')
let dynamicStateModel = mongoose.model("dynamicState", dynamicState, 'dynamicState')
let chatModel = mongoose.model("chat", chatSchema, 'chat')
module.exports = {
  UserModel, CartModel, SizeModel, OrderModel, ancientModel,
  authorModel,
  typeModel,
  dynamicStateModel,
  merchantModel,
  ShopCarModel,
  chatModel
}